·<template>
  <div class="app-container">
    <div v-show="active === 1">
      <div class="searchform">
        <!-- 查询条件 -->
        <el-form ref="searchForm" :model="search" size="mini" label-width="90px" label-position="right">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="employeeNo" label="员工编号">
                <el-input v-model="search.employeeNo" placeholder="员工编号" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="userCode" label="账号">
                <el-input v-model="search.userCode" placeholder="账号" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="employeeName" label="姓名">
                <el-input v-model="search.employeeName" placeholder="姓名" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="workingState" label="在职状态">
                <r-select v-model="search.workingState" type="1008" placeholder="请选择" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="userState" label="用户状态">
                <r-select v-model="search.userState" type="1003" placeholder="请选择" clearable/>
              </el-form-item>
            </el-col>
            <div style="text-align:right">
              <el-button type="primary" icon="el-icon-search" @click="searchHandle">查询
              </el-button>
              <el-button icon="el-icon-refresh" @click="resetForm('searchForm')">重置
              </el-button>
            </div>
          </el-row>
        </el-form>
      </div>
      <div class="table">
        <div class="tableHead">
          <div class="tabletitle">用户信息</div>
          <div class="btnGroup">
            <el-button-group>
              <el-button type="primary" icon="el-icon-refresh" @click="restClick" >重置密码</el-button>
            </el-button-group>
          </div>
        </div>
        <!-- 用户列表 -->
        <baseTable ref="table" @chaneg-size="changeSizeHandle" @chaneg-page="changePageHandle" @selection-change="handleSelectionChangePwd" >
          <el-table-column label="序号" type="index" min-width="50"/>
          <el-table-column :selectable="checkSelectable" type="selection" width="50"/>
          <el-table-column align="center" label="操作" width="150">
            <template slot-scope="scope">
              <el-tooltip class="item" content="编辑" placement="bottom">
                <el-button :disabled="scope.row.IS_ONJOB === '10081002' || (scope.row.USER_CODE === userInfo.dealerCode && (scope.row.IS_BIG_CUSTOMER != 10041001 && scope.row.USER_CODE != '0008' && scope.row.USER_CODE != '0002' ) )" type="text" style="font-size: 20px;" icon="el-icon-edit-outline" @click="edit(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="明细" placement="bottom">
                <el-button type="text" style="font-size: 20px;" icon="el-icon-document" @click="detail(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="解锁" placement="bottom">
                <el-button
                  :disabled="scope.row.LOCK_FLAG === 10041002 || scope.row.USER_CODE === userInfo.dealerCode"
                  type="text"
                  style="font-size: 20px;"
                  icon="el-icon-sold-out"
                  @click="removelock(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="锁定" placement="bottom">
                <el-button :disabled="scope.row.LOCK_FLAG === 10041001 || scope.row.IS_ONJOB === '10081002' || scope.row.USER_CODE === userInfo.dealerCode" type="text" style="font-size: 20px;" icon="el-icon-goods" @click="lock(scope.row)"/>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column prop="EMPLOYEE_NO" label="员工编号" min-width="150"/>
          <el-table-column prop="USER_CODE" label="账号" width="150"/>
          <el-table-column v-if="false" prop="USER_ID"/>
          <el-table-column prop="EMPLOYEE_NAME" label="姓名" width="120"/>
          <el-table-column prop="IS_ONJOB" label="在职状态" min-width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.IS_ONJOB === 10081001 ? 'success' : 'primary'" close-transition>{{ scope.row.IS_ONJOB
              | isONJOB }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="USER_STATUS" label="状态" min-width="80">
            <template slot-scope="scope">
              <el-tag :type="scope.row.USER_STATUS === 10031001 ? 'success' : 'primary'" close-transition>{{ scope.row.USER_STATUS
              | isSTATUS }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="ROLE_NAME" label="员工岗位" min-width="120"/>
          <el-table-column prop="LOCK_FLAG" label="是否锁定" min-width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.LOCK_FLAG === 10041001 ? 'success' : 'primary'" close-transition>{{ scope.row.LOCK_FLAG
              | isYESORNO }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="DATA_SOURCES" label="数据来源" min-width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.DATA_SOURCES === 10461001 ? 'success' : 'primary'" close-transition>{{ scope.row.DATA_SOURCES
              | isSOURCES }}
              </el-tag>
            </template>
          </el-table-column>
        </BaseTable>
      </div>
    </div>
    <!-- 修改界面-->
    <div v-show="active === 2">
      <el-form ref="form" :model="form" :rules="rules" :disabled="type1==='detail'" inline size="mini" label-width="70px">
        <el-collapse v-model="model">
          <div class="tableHead">
            <div class="tabletitle">用户权限编辑</div>
            <div class="btnGroup">
              <el-button-group>
                <template slot-scope="scope">
                  <el-button size="mini" type="primary" icon="el-icon-edit" @click="rolePermission">角色模板</el-button>
                  <el-button :disabled="!userCodeShow" type="primary" size="mini" icon="el-icon-edit" @click="changePassword(scope.row)">修改密码</el-button>
                </template>
              </el-button-group>
            </div>
          </div>

          <div class="searchform">
            <el-form-item label="员工编号" prop="employeeNo">
              <el-input v-model="form.EMPLOYEE_NO" disabled placeholder="员工编号" />
            </el-form-item>
            <el-form-item label="账号" prop="USER_CODE">
              <el-input v-model="form.USER_CODE" disabled placeholder="账号" />
            </el-form-item>
            <el-form-item label="姓名" prop="employeeName">
              <el-input v-model="form.EMPLOYEE_NAME" disabled placeholder="姓名" />
            </el-form-item>
            <el-form-item prop="userState" label="用户状态">
              <r-select v-model="form.USER_STATUS" type="1003" />
            </el-form-item>
            <el-form-item label="职责" prop="employeeRoles">
              <el-checkbox-group v-model="checkedList">
                <el-checkbox v-for="role in sites" :label="role.ROLE_ID" :key="role.ROLE_ID" :value="role.ROLE_ID" :disabled="true">
                  {{ role.ROLE_NAME }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </div>
          <el-collapse-item name="1" title="权限管理">
            <div class="grid-content bg-purple">菜单权限</div>
            <el-scrollbar style="height: 350px;border: 1px solid rgba(144,147,153,.5);">
              <el-tree
                v-loading="loading"
                ref="tree"
                :data="jsonTree"
                :expand-on-click-node="false"
                style="margin-top: 12px;"
                show-checkbox
                node-key="id"
                highlight-current
                @node-click="nodeClickHandle" />
            </el-scrollbar>
          </el-collapse-item>
        </el-collapse>
      </el-form>
      <div style="text-align:center">
        <el-button v-show="type1==='edit'" type="primary" @click="confirmHandle2">保存</el-button>
        <el-button @click="cancel">返回</el-button>
      </div>
    </div>
    <!-- 弹框角色模板 -->
    <el-dialog
      ref="dia"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="dialogVisible"
      :append-to-body="true"
      title="角色模板"
      custom-class="r-dialog"
      top="5vh"
      width="50%">
      <div class="searchform">
        <el-form ref="searchForm1" :model="search2" size="mini" label-width="90px">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item prop="roleCode" label="角色代码">
                <el-input v-model="search2.roleCode" placeholder="角色代码" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="8">
              <el-form-item prop="roleName" label="角色名称">
                <el-input v-model="search2.roleName" placeholder="角色名称" />
              </el-form-item>
            </el-col>
            <div style="text-align:right;">
              <el-button type="primary" icon="el-icon-search" @click="searchRole">查询
              </el-button>
              <el-button icon="el-icon-refresh" @click="resetForm('searchForm1')">重置
              </el-button>
            </div>
          </el-row>
        </el-form>
      </div>
      <div class="table">
        <div class="tableHead">
          <div class="tabletitle">角色信息</div>
        </div>
        <el-table
          ref="table1"
          :data="list"
          tooltip-effect="dark"
          style="width: 100%"
          stripe
          border
          @selection-change="handleSelectionChange">
          <el-table-column label="序号" type="index" min-width="50"/>
          <el-table-column type="selection" width="50"/>
          <el-table-column prop="ROLE_CODE" label="角色代码" min-width="50"/>
          <el-table-column prop="ROLE_NAME" label="角色名称" min-width="50"/>
          <el-table-column prop="DATA_SOURCE" label="数据来源" min-width="50">
            <template slot-scope="scope">
              <filtercode v-model="scope.row.DATA_SOURCE" type="1046" />
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <Pagination :data="page" style="text-align:center" @change-size="handleSizeChange" @change-page="handleCurrentChange" />
      <div style="text-align:center">
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="confirmHandle">确 定</el-button>
          <el-button @click="dialogVisible = false">取 消</el-button>

        </span>
      </div>
      <br >
    </el-dialog>
    <!-- 弹框修改密码 -->
    <el-dialog
      ref="passwordRef"
      :visible.sync="dialogVisible1"
      :append-to-body="true"
      title="更改密码"
      custom-class="r-dialog"
      top="5vh"
      width="75%">
      <div class="elform">
        <el-form ref="password" :inline="true" :rules="passwordRules" :model="form1" size="mini" label-width="90px">
          <el-form-item prop="USER_CODE1" label="账号">
            <el-input v-model="USER_CODE1" disabled placeholder="账号" />
          </el-form-item>
          <el-form-item prop="EMPLOYEE_NAME1" label="姓名">
            <el-input v-model="EMPLOYEE_NAME1" disabled placeholder="姓名" />
          </el-form-item>
          <el-form-item prop="passwordModel" label="新密码">
            <el-input v-model="form1.passwordModel" type="password" placeholder="请输入8~15位密码" />
            <!-- <span>{{passwordValidate.errorText}}</span> -->
          </el-form-item>
          <el-form-item prop="passwordcheckModel" label="确认密码">
            <el-input v-model="form1.passwordcheckModel" type="password" placeholder="确认密码" />
            <!-- <span>{{passwordCheckValidate.errorText}}</span> -->
          </el-form-item>

        </el-form>
      </div>
      <div style="text-align:center">
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="confirmHandle1">确 定</el-button>
          <el-button @click="dialogVisible1 = false">取 消</el-button>

        </span>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getJsonTree
} from '@/api/admin/utils/index'
import {
  searchRoleEmp,
  supereditpassword,
  findByEmployeeId,
  ModifyOrg,
  userDataVue,
  removeLockflag,
  roleData,
  lockflag
} from '@/api/admin/auth/employeePermissionInfo'
import { restPassword } from '@/api/admin/auth/gms/user'
import {
  getRoleList,
  getMenu
} from '@/api/admin/auth/roleManage'
import {
  findEmployeeRoleById,
  findEmpRoles
} from '@/api/admin/org/employeeInfo'

import BaseTable from '@/components/BaseTable'
import Pagination from '@/components/Pagination'
import BaseDialog from '@/components/BaseDialog'
import formMixins from '@/mixins/formMixins'
import rSelect from '@/components/Select/Select'
import filtercode from '@/components/Checkbox/filtercode'
import _ from 'lodash'
import {
  mapGetters
} from 'vuex'
import {
  passWD
} from '@/utils/validator'
export default {
  name: 'EmployeePermissionInfo',
  components: {
    BaseTable,
    BaseDialog,
    rSelect,
    Pagination,
    filtercode
  },
  // 过滤器
  filters: {
    isYESORNO(val) {
      return val === 10041001 ? '是' : '否'
    },
    isSOURCES(val) {
      return val === 10461001 ? '店面' : '厂端'
    },
    isSTATUS(val) {
      return val === 10031001 ? '启用' : '禁用'
    },
    isONJOB(val) {
      return val === 10081001 ? '在职' : '离职'
    }
  },
  mixins: [formMixins],
  data() {
    const validatePasswordModel = (rule, value, callback) => {
      if (_.isEmpty(value)) {
        callback(new Error('请输入新密码'))
      } else {
        passWD(rule, value, callback)
      }
    }
    const validatePasswordcheckModel = (rule, value, callback) => {
      if (_.isEmpty(value)) {
        callback(new Error('请输入确认密码'))
      } else {
        if (value !== this.form1.passwordModel) {
          callback(new Error('确认密码值和新密码值不一致'))
        }
        passWD(rule, value, callback)
      }
    }
    return {
      reList: [],
      type1: '',
      checkedListMenus: [],
      checkedListMenuL: [],
      menuId: '',
      checkedListMenuLRange: [],
      dialogVisible: false,
      dialogVisible1: false,
      dialogFormVisible: false,
      userCodeShow: true,
      password: {
        newPassword: '',
        confirmPassword: ''
      },
      tree: [],
      multipleSelection: [],
      multipleSelectionPwd: [],
      defaultProps: {
        children: 'children',
        label: 'text'
      },
      rules: {
        USER_CODE: [{
          required: true,
          message: '请输入账号',
          trigger: 'blur'
        }
        ]
      },
      passwordRules: {
        passwordModel: [{
          required: true,
          trigger: 'blur',
          validator: validatePasswordModel
        }],
        passwordcheckModel: [{
          required: true,
          trigger: 'blur',
          validator: validatePasswordcheckModel
        }]
      },
      list: [],
      loading: false,
      rangeloading: false,
      actionloading: false,
      load: false,
      page: {},
      active: 1,
      model: '1',
      form1: {
        passwordModel: '',
        passwordcheckModel: ''
      },
      form: {
        EMPLOYEE_NO: '',
        EMPLOYEE_ID: '',
        USER_CODE: '',
        EMPLOYEE_NAME: '',
        USER_STATUS1: ''
      },
      form2: {},
      search2: {
        limit: 10,
        pageNum: 1,
        roleCode: '',
        roleName: '',
        dataType: 10461001,
        dataSource: 10451001,
        isDealer: 'true'
      },
      search: {
        limit: 10,
        pageNum: 1,
        employeeNo: '',
        userCode: '',
        employeeName: '',
        workingState: '',
        userState: ''
      },
      menuRangeList: [],
      menuActionList: [],
      checkedList: [],
      sites: [],
      objRange: [],
      sites1: [],
      sites2: [],
      passwordModel: '',
      passwordcheckModel: '',
      EMPLOYEE_NAME1: '',
      USER_CODE1: '',
      USER_STATUS1: '',
      USER_ID: '',
      checkedPartList: [],
      checkedJpckList: [],
      checkedListRepairRepair: [],
      checkedPartPartList: [],
      checkedListVec: [],
      checkedDiscountModeList: [],
      roleId: ''
    }
  },
  computed: {
    ...mapGetters(['dictMap', 'regionMap', 'userInfo']),
    jsonTree() {
      this.tree.forEach(el => (el.label = el.text))
      this.tree.forEach(el => (el.parentId = el.parent))
      return getJsonTree(this.tree)
    },
    passwordValidate: function() {
      var errorText
      if (!/^[0-9A-Za-z]{6,15}$/.test(this.passwordModel)) {
        errorText = '密码少于6位'
      } else {
        errorText = ''
      }
      if (!this.passwordFlag) {
        errorText = ''
        this.passwordFlag = true
      }
      return {
        errorText
      }
    },
    passwordCheckValidate: function() {
      var errorText
      if (!this.passwordcheckModel) {
        errorText = ''
      } else if (!/^[0-9A-Za-z]{6,15}$/.test(this.passwordcheckModel)) {
        errorText = '密码少于6位'
      } else if (this.passwordcheckModel !== this.passwordModel) {
        errorText = '两次密码不匹配'
      } else {
        errorText = ''
      }
      if (!this.passwordFlag) {
        errorText = ''
        this.passwordFlag = true
      }
      return {
        errorText
      }
    }
  },
  watch: {
    multipleSelection: function() {
      const arr = []
      for (const i in this.multipleSelection) {
        arr.push(this.multipleSelection[i].id)
      }
      console.log('勾中的id为：' + arr.join())
    }
  },
  mounted() {
    this.searchHandle()
    this.searchTree()
  },
  methods: {
    // 加载树
    searchTree() {
      this.loading = true
      const param = {
        roleId: this.roleId,
        userId: this.USER_ID
      }
      getMenu(param)
        .then(res => {
          this.loading = false
          this.deleteRes(res.treejson)
          this.tree = res.treejson
          console.log(res.treejson)
        })
        .catch(err => {
          this.loading = false
        })
    },
    // 删除无效数据(无父节点)
    deleteRes(res) {
      const result = []
      for (let i = 0; i < res.length && res[i].id != null; i++) {
        const pid = res[i].parent
        const oid = res[i].id
        result[oid] = pid
      }
      for (let j = 0; j < res.length; j++) {
        // 一级父节点跳过
        if (res[j].parent === '#') continue
        if (res[j] && result[res[j].parent] === null) {
          const index = j
          j = 0
          delete result[res[index].id]
          res.splice(index, 1)
        }
      }
    },
    checkSelectable(row) {
      return row.USER_CODE != null
    },
    handleSelectionChangePwd(val) {
      this.multipleSelectionPwd = val
    },
    // 获取多选参数
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 角色选择分页
    handleSizeChange(size) {
      this.search2.limit = size
      this.searchRole()
    },
    handleCurrentChange(page) {
      this.search2.pageNum = page
      this.searchRole()
    },
    // 主列表界面查询
    searchHandle() {
      const table = this.$refs['table']
      searchRoleEmp(this.search)
        .then(res => {
          table.complete().filData(res)
        })
        .catch(err => {
          table.complete()
        })
    },
    // 明细
    detail(data) {
      this.type1 = 'detail'
      this.active = 2
      this.searchTree()
      this.USER_STATUS1 = data.USER_STATUS
      this.USER_ID = data.USER_ID
      const id = 'employeeId=' + data.EMPLOYEE_ID + '&dataSource=' + data.DATA_SOURCES
      // 查询赋值
      userDataVue(id).then(res => {
        this.refreshMenut(res)
      })
      findByEmployeeId(data.EMPLOYEE_ID)
        .then(res => {
          this.form = _.cloneDeep(res)
        })
        .catch(err => {
        })
        // 职责复选框选中数据
      this.EmployeeRolesCheck(data.EMPLOYEE_ID)
    },
    // 点击修改
    edit(data) {
      this.userCodeShow = false
      this.type1 = 'edit'
      this.active = 2
      this.USER_STATUS1 = data.USER_STATUS
      this.USER_ID = data.USER_ID
      const id = 'employeeId=' + data.EMPLOYEE_ID + '&dataSource=' + data.DATA_SOURCES
      this.roleId = data.EMPLOYEE_ID
      this.searchTree()
      // 查询赋值
      userDataVue(id).then(res => {
        this.refreshMenut(res)
      })
      findByEmployeeId(data.EMPLOYEE_ID)
        .then(res => {
          // res.forEach(item => {
          this.form = _.cloneDeep(res)
          if (res.USER_CODE === null) {
            this.userCodeShow = false
            this.form.USER_CODE = this.form.EMPLOYEE_NO
          }
          // })
        })
        .catch(err => {
          // table.complete()
        })
        // 职责复选框选中数据
      this.EmployeeRolesCheck(data.EMPLOYEE_ID)
    },
    // 职责复选框查询
    getEmployeeRoles(type) {
      // const type = 1006;
      findEmpRoles(this.userInfo.dealerCode)
        .then(res => {
          this.sites = _.cloneDeep(res)
        })
        .catch(err => {
          // table.complete()
        })
    },
    // 职责复选框查询
    EmployeeRolesCheck(id) {
      const type = 1006
      this.getEmployeeRoles(type)
      const checkedLists = []
      findEmployeeRoleById(id)
        .then(res => {
          for (let i = 0; i < res.length; i++) {
            checkedLists.push(res[i].CODE_ID)
          }
          this.checkedList = checkedLists
        })
        .catch(err => {
          // table.complete()
        })
    },
    // 解锁
    removelock(data) {
      this.$confirm('是否解锁', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          removeLockflag(data.EMPLOYEE_ID).then(res => {
            this.$message({
              type: 'success',
              message: '解锁成功!'
            })
            this.searchHandle()
          })
            .catch(err => {
            })
        })
        .catch(err => {
          this.$message({
            type: 'info',
            message: '已取消解锁'
          })
        })
    },
    // 锁定
    lock(data) {
      this.$confirm('是否锁定', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          lockflag(data.EMPLOYEE_ID).then(res => {
            this.$message({
              type: 'success',
              message: '锁定成功!'
            })
            this.searchHandle()
          })
            .catch(err => {
            })
        })
        .catch(err => {
          this.$message({
            type: 'info',
            message: '已取消锁定'
          })
        })
    },
    // 角色查询
    searchRole() {
      this.search2.dataType = this.userInfo.dataType
      this.load = true
      getRoleList(this.search2)
        .then(res => {
          this.list = res.rows
          this.page = res
          this.load = false
        })
        .catch(err => {
          this.load = false
        })
    },
    // 重置密码
    restClick() {
      if (this.multipleSelectionPwd.length !== 0) {
        let empIds = ''
        this.multipleSelectionPwd.forEach(item => {
          if (empIds === '') {
            empIds = item['EMPLOYEE_ID']
          } else {
            empIds = empIds + ',' + item['EMPLOYEE_ID']
          }
        })
        const param = {
          empIds: empIds,
          newPassword: 'SHANTUI123456'
        }
        restPassword(param)
          .then(() => {
            this.$message({
              type: 'success',
              message: '重置密码成功!'
            })
          }).catch(err => {

          })
      } else {
        this.$message({
          type: 'warning',
          message: '请选择表格数据'
        })
      }
    },
    // 角色模板
    rolePermission() {
      this.dialogVisible = true
      this.searchRole()
    },
    // 保存角色
    confirmHandle() {
      // 获取当前选择行的 ROLE_ID
      let roleIds
      const val = this.multipleSelection
      if (val.length <= 0) {
        this.$message({
          type: 'info',
          message: '请选择数据'
        })
        return
      }
      for (let i = 0; i < val.length; i++) {
        if (!roleIds) {
          roleIds = val[i].ROLE_ID
        } else {
          roleIds += ',' + val[i].ROLE_ID
        }
      }
      roleData(roleIds)
        .then(res => {
          this.$message({
            type: 'success',
            message: '保存成功  '
          })
          this.form.roleId = roleIds
          this.dialogVisible = false
          // 刷新权限管理
          this.refreshMenut(res)
        })
        .catch(err => {
        })
    },
    // 修改密码
    changePassword(data) {
      this.dialogVisible1 = true
      this.USER_CODE1 = this.form.USER_CODE
      this.EMPLOYEE_NAME1 = this.form.EMPLOYEE_NAME
    },
    // 修改密码确定
    confirmHandle1() {
      this.$refs['password'].validate((valid) => {
        if (valid) {
          this.form2.employeeId = this.form.EMPLOYEE_ID
          this.form2.userCode = this.form.USER_CODE
          this.form2.newPassword = this.form1.passwordModel
          supereditpassword(this.form2)
            .then(res => {
              this.$message({
                type: 'success',
                message: '修改成功！  '
              })
              this.dialogVisible1 = false
            })
            .catch(err => {
            })
        }
      })
    },
    // 修改界面点击树形
    nodeClickHandle(data) {
      const {
        id,
        text
      } = data
      this.text = text
      // this.loading = true;
      this.searchMenuHandle(id)
    },
    searchMenuHandle(id) {
      if (id) {
        this.$set(this.search, 'parentOrg', id)
      }
      this.menuId = id
    },
    // 编辑保存
    confirmHandle2() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          // this.loading = true;
          const selectedNode = this.$refs['tree'].getCheckedKeys() // 父节点
          const selectedHalfNode = this.$refs['tree'].getHalfCheckedKeys() // 子节点
          const allNode = selectedHalfNode.concat(selectedNode)
          // const list = this.$refs.tree.getCheckedNodes(true)
          // const test = list.join(',')
          const params = {
            employeeId: this.form.EMPLOYEE_ID,
            dataSource: this.form.DATA_SOURCES,
            employeeNo: this.form.EMPLOYEE_NO,
            thisUserCode: this.form.USER_CODE,
            employeeName: this.form.EMPLOYEE_NAME,
            employeeRoleIds: this.form.roleId,
            userCode: this.form.USER_CODE,
            userStatus: this.USER_STATUS1,
            employeeRoles: this.checkedList,
            nowTree: allNode.join(',')
          }
          ModifyOrg(params)
            .then(res => {
              this.$message({
                type: 'success',
                message: '保存成功!'
              })
              this.active = 1
              this.searchHandle()
            })
            .catch(err => {
            })
        }
      })
    },
    refreshMenut(res) {
      const restreejson = res.treejson
      const result = []
      for (let i = 0; i < restreejson.length && restreejson[i].id != null; i++) {
        const pid = restreejson[i].parent
        const oid = restreejson[i].id
        result[oid] = pid
      }
      for (let j = 0; j < restreejson.length; j++) {
        const states = restreejson[j].state
        if (states.checked === false) {
          const index = j
          j = 0
          delete result[restreejson[index].id]
          restreejson.splice(index, 1)
        }
      }
      // const arr = findArrKey(restreejson)[0] === 10 ? [] : findArrKey(restreejson)
      // log('current user permission: ', arr)
      /**
            * 勾选菜单
            */
      const selectedmenu = []
      for (let j = 0; j < restreejson.length; j++) {
        const states = restreejson[j].state
        if (states.checked === true) {
          selectedmenu.push(restreejson[j].id)
        }
      }
      this.$refs['tree'].setCheckedKeys(selectedmenu)
      console.log(selectedmenu)
      console.log(this.$refs['tree'].getCheckedKeys())
      // this.checkedListMenuL = res.treeMenuRange;
      // this.checkedListMenus = res.treeMenuAction;
    },
    // 返回清空列表
    cancel() {
      this.active = 1
      this.form = {}
      this.sites1 = []
      this.sites2 = []
      this.$refs['tree'].setCheckedKeys(this.reList)
      this.checkedListMenuL = []
      this.checkedListMenus = []
      this.searchHandle()
    }
  }
}

</script>

<style scoped>
  .el-checkbox+.el-checkbox {
    margin-left: 0px;
  }

  .el-checkbox {
    margin-right: 25px;
  }

  .menu-header {
    height: 30px;
    line-height: 30px;
    margin-bottom: 5px;
    background: #eee;
    text-indent: 5px;
  }

</style>
